/* $Id: ContestLanguagesFormatter.java 110 2011-01-24 21:33:40Z altdotua@gmail.com $ */

package alt.djudge.frontend.server.gui;

import java.util.Map;

import alt.djudge.frontend.server.datatypes.ContestEntry;
import alt.djudge.frontend.server.datatypes.ContestLanguageEntry;
import alt.djudge.frontend.server.datatypes.LanguageEntry;
import alt.djudge.frontend.server.models.ContestsModel;
import alt.djudge.frontend.server.models.LanguagesModel;
import alt.djudge.frontend.server.utils.Linker;


public class ContestLanguagesFormatter extends AbstractFormatter<ContestLanguageEntry>
{
	private Map<Long, LanguageEntry> languagesMap = LanguagesModel.getEntriesMap();
	
	private Map<Long, ContestEntry> contestsMap = ContestsModel.getEntriesMap();
	
	private boolean addCommands = false;
	
	private String returnTo = null;
	
	public ContestLanguagesFormatter()
	{
		// TODO Auto-generated constructor stub
	}
	
	public ContestLanguagesFormatter(boolean commands)
	{
		this.addCommands = commands;
	}
	
	public ContestLanguagesFormatter(boolean commands, String returnToUrl)
	{
		this.addCommands = commands;
		this.returnTo = returnToUrl;
	}
	
	@Override
	protected void addClassData(ContestLanguageEntry l)
	{
		addTableData(l.getId());
		addTableData(contestsMap.get(l.getContestId()).getSid());
		addTableData(languagesMap.get(l.getLanguageId()).getSid());
		addTableData(l.getVisible());
		if (addCommands)
		{
			addTableData("Delete", Linker.link("contestlanguages?action=delete&id=" + l.getId() + (returnTo != null ? "&return=" + returnTo : "")));
			addTableData("Edit", Linker.link("admin/contestlanguages.jsp?id=" + l.getId()));
			addTableData("Copy", Linker.link("contestlanguages?action=copy&id=" + l.getId() + (returnTo != null ? "&return=" + returnTo : "")));
		}
	}

	@Override
	protected void addClassHeaders()
	{
		addTableHeader("ID");
		addTableHeader("Contest");
		addTableHeader("Language");
		addTableHeader("Active");
		if (addCommands)
		{
			addTableHeader("Delete");
			addTableHeader("Edit");
			addTableHeader("Copy");
		}
	}

	@Override
	protected String getCustomRowClass(ContestLanguageEntry entry)
	{
		// TODO Auto-generated method stub
		return null;
	}
}
